<!DOCTYPE html>
<html lang="en">
<head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     <title>Canvas mouse move stroke line</title>
     <script>
          window.onload = function () {
               let oc = document.getElementById('canvas')
               let sColor = document.getElementById('colors')
               let gd = oc.getContext('2d')
               let color = '#ff6666'

               sColor.addEventListener('change', function () {
                    color = this.value
                    console.log(color)
               }, false)
               
               let lastX, lastY
               oc.onmousedown = function (ev) {
                    lastX = ev.offsetX
                    lastY = ev.offsetY

                    oc.onmousemove = function (ev) {
                         let curX = ev.offsetX
                         let curY = ev.offsetY
                         gd.beginPath()
                         gd.moveTo(lastX, lastY)
                         gd.lineTo(curX, curY)

                         lastY = curY
                         lastX = curX
                         gd.strokeStyle = color
                         gd.stroke()
                    }

                    oc.onmouseup = function () {
                         oc.onmousedown = null
                         oc.onmousemove = null
                    }
               }
          }
     </script>
</head>
<body>
     <input type="color" id="colors" />
     <canvas id="canvas" width="800" height="600"></canvas>
</body>
</html>